/**
 * 页面定制公共事件
 */
export default {
    data() {
        return {
        }
    },
    created() {
        this.initEvent();
    },
    beforeDestroy() {
        //销毁事件
        this.$bus.off("formEvent");
        this.$bus.off("chartEvent");
        this.$bus.off("customViewEvent");
        this.$bus.off("calendarViewEvent");
        this.$bus.off("filterEvent");
        this.$bus.off("formCustomPublicEvent");
    },
    methods:{
        /**
         * 初始化事件
         */
        initEvent(){
            var self_=this;
            this.$bus.on('formEvent',  (args)=> {
                self_.handReceive(args,self_)
            });
            this.$bus.on('chartEvent',  (args)=> {
                self_.handReceive(args,self_)
            });
            this.$bus.on('customViewEvent',  (args)=> {
                self_.handReceive(args,self_)
            });
            this.$bus.on('calendarViewEvent',  (args)=> {
                self_.handReceive(args,self_)
            });
            this.$bus.on('filterEvent',  (args)=> {
                self_.handReceive(args,self_);
            });
            /**
             * 页面定制公共事件
             */
            this.$bus.on('formCustomPublicEvent',  (conf)=> {
                self_.handPublicEvent(conf,self_);
            });
        },
        getRouterParams(){
            var params =this.$route.params || {};
            if (this.$route.meta.params) {
                params =Object.assign(params,JSON.parse(this.$route.meta.params));
            }
            if (this.$route.query) {
                params =Object.assign(params,this.$route.query);
            }
            return params;
        },

        /**
         * {component: "控件key", params: {传递参数}}
         * @param conf
         */
        handPublicEvent(conf){
            if(this.layoutItem && this.layoutItem.id==conf.component){
                if(this.handPublicReceive){
                    this.handPublicReceive(conf);
                }
            }
        }
    }
}